package nc.tb.pub.ref;

import nc.tb.dim.data.DimManager;
import nc.tb.dim.data.SumManager;
import nc.tb.pub.IBusiObj;
import nc.tb.pub.IDimType;
import nc.tb.pub.util.NtbLogger;
import nc.vo.pub.BusinessException;

public class DimDefRefPane extends FreeTypeRefPane {

	private String m_dimType;
	
	public DimDefRefPane(String dimType) {
		super();
		m_dimType = dimType;
	}
	
	public DimDefRefPane(String title, String dimType) {
		super(title);
		m_dimType = dimType;
	}
	
	public void onButtonClicked() {
    	IBusiObj result = null;
    	FreeTypeRefUI m_refPnlUI = new FreeTypeRefUI(this, m_Title);
    	try {
			leafObjs = IDimType.SUM.equals(m_dimType) ? SumManager.getSumDefs(m_dimType) 
					: DimManager.getDimDefs(m_dimType);
		} catch (BusinessException e) {
			NtbLogger.printException(e);
			return;
		}
    	if (m_root != null)
    		m_refPnlUI.setTreeValues(m_root, leafObjs);
    	else if (m_rootName != null)
    		m_refPnlUI.setTreeValues(m_rootName, leafObjs);
    	else {
    		m_refPnlUI.destroy();
    		return;
    	}
        if (m_refPnlUI.showModal() == nc.ui.pub.beans.UIDialog.ID_OK) {
        	result = m_refPnlUI.getBusiobj();
        }
        if (result != null)
        	setSelectedBusiObj(result);
        m_refPnlUI.destroy();
    }
}
